// xc_lshop/shop/activity/actlist.js
var actbill = require('../model/activity_list')
var actprobill = require('../../../xc/model/pro_contents')

Page({
  mixins: [require('../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    selected:{}
  },
  buyop: function (ev) {
     //活动未开始/结束/下架不能购买 达到上限
    if ((!this.data.activity) || this.data.activity.actstatus != 1) {
      return;
    }
    if (!this.data.memberinfo) {
      this.login();
    }

    

    var dataset = ev.currentTarget.dataset
  //   if(this.data.activity.itype==2){
  //     wx.navigateTo({
  //       url: '/xc_lshop/shop/pro/proinfo?id='+dataset.id+'&activityid='+this.data.activity.id,
  //     })

  //     return;
  //  }
  


    var that = this
    var option = "";
    if (this.data.activity.id) {
      option = {
        aid: this.data.activity.id,
        atype: this.data.activity.itype
      }
    }
    console.log("dataset.id")
    console.log(dataset.id)
    console.log(that.data.selected[dataset.id])
    console.log(option)
    actprobill.showattrchose(that,dataset.id,  that.data.selected[dataset.id],this.data.activity.itype==3?2:3, option)
  },
  attrchoose: function (e) {
    var choosed = e.detail;
      var selected=this.data.selected;
      selected[choosed.proid]=e.detail
      this.setData({
        selected: selected
      })
  },
  getconfig(config){
    var that = this;
    var updatedata = {};
    if (config.prothem) {
      if (config.prothem.themcolor) {
        var themconfig = config.prothem.themcolor.config;
        updatedata['themconfig'] = themconfig
      }
      if (config.prothem.popup) {
        var popconfig = config.prothem.popup.proconfig;
        var popCustomStyle = config.prothem.popup.customStyle;
        updatedata['popconfig'] = popconfig
        updatedata['popCustomStyle'] = popCustomStyle
      }
      if (config.task){
        updatedata['taskname'] = config.task.taskname

      }
    }
    that.setData(updatedata)
  },
  xcloaddata: function (options, config) {
    
    this.getconfig(config)
    this.getmodel(options.activityid)
  },
  // 注册
  login() {
    var app = getApp()
    var that = this
    app.xc_sys_config.authop.oppower("login").then(function (res) {
      that.setData({
        "memberinfo": app.globalData.member.memberinfo
      })
    })
  },
  afterlogin: function (options, config, userinfo) {
    if (userinfo.memberinfo) {
      this.setData({
        memberinfo: userinfo.memberinfo
      })
    }
  },
  getpagelist(that, rest, strwhere) {
    if (rest == 1) {
      if(!strwhere)
      {
        strwhere={}
      }
      // strwhere["status"] = this.data.activetab
      that.setData({
        modellist: []
      });
    }
    actbill.offset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};
      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {
        // if(result["obj"]["modellist"].length<1){
        //   updatemdoel["isempty"]=true
        // }
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        } else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);            
          }           
        }
      }
      console.log()     
      wx.stopPullDownRefresh();
      that.setData(updatemdoel);
    }, function () {

    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  //获取活动数据 actstatus-2下架 -1未开始 1进行中 2已结束
  getmodel(id){
    var that=this;
    actbill.getmodel(id).then(function(res){
      if(res['status']==1){
        // console.log(res['obj'])
         that.setData({
           activity:res['obj']
         })

        //  that.getpagelist(that,1,{activityid:id,ids:res['obj'].proids})
      }
    })
  },
  onChangeDate(e) {
    this.setData({
      timeData:  e.detail
    });
  },
  //倒计时结束
  onFinishDate(e){
    var update={};
    if(this.data.activity.actstatus==1){
      update['activity.actstatus']=2
    }else if(this.data.activity.actstatus==-1){
      update['activity.actstatus']=1
    }
    this.setData(update)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
})